﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_menu_acl : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainMenuAclAbility");

            migrationBuilder.DropTable(
                name: "MainMenuAclRole");

            migrationBuilder.DropColumn(
                name: "I18n",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "Link",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "Target",
                table: "MainMenu");

            migrationBuilder.RenameColumn(
                name: "OpenFlag",
                table: "MainMenu",
                newName: "HideInMenuFlag");

            migrationBuilder.AlterColumn<string>(
                name: "MenuName",
                table: "MainMenu",
                type: "text",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "character varying(100)",
                oldMaxLength: 100);

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                table: "MainMenu",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "character varying(256)",
                oldMaxLength: 256,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ExternalLink",
                table: "MainMenu",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "character varying(200)",
                oldMaxLength: 200,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Acl",
                table: "MainMenu",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ExternalLinkTarget",
                table: "MainMenu",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MenuCatgeCodg",
                table: "MainMenu",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MenuCatgeName",
                table: "MainMenu",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "RouteAddr",
                table: "MainMenu",
                type: "text",
                nullable: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Acl",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "ExternalLinkTarget",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "MenuCatgeCodg",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "MenuCatgeName",
                table: "MainMenu");

            migrationBuilder.DropColumn(
                name: "RouteAddr",
                table: "MainMenu");

            migrationBuilder.RenameColumn(
                name: "HideInMenuFlag",
                table: "MainMenu",
                newName: "OpenFlag");

            migrationBuilder.AlterColumn<string>(
                name: "MenuName",
                table: "MainMenu",
                type: "character varying(100)",
                maxLength: 100,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                table: "MainMenu",
                type: "character varying(256)",
                maxLength: 256,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ExternalLink",
                table: "MainMenu",
                type: "character varying(200)",
                maxLength: 200,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "I18n",
                table: "MainMenu",
                type: "character varying(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Link",
                table: "MainMenu",
                type: "character varying(200)",
                maxLength: 200,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Target",
                table: "MainMenu",
                type: "character varying(256)",
                maxLength: 256,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "MainMenuAclAbility",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    Ability = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMenuAclAbility", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMenuAclAbility_MainMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "MainMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainMenuAclRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    RoleCode = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMenuAclRole", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMenuAclRole_MainMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "MainMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainMenuAclAbility_MenuId",
                table: "MainMenuAclAbility",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMenuAclRole_MenuId",
                table: "MainMenuAclRole",
                column: "MenuId");
        }
    }
}
